package com.happy3w.ssp.schoolmatehome.repository;

import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class FollowRepository {
    private final JdbcTemplate jdbcTemplate;

    public void markFollow(Long userId, Long fanId) {
        jdbcTemplate.update("INSERT IGNORE INTO follow_state (user_id, fans_id, created_at) VALUES (?, ?, NOW())",
                userId, fanId);
    }

    public void unmarkFollow(Long userId, Long fanId) {
        jdbcTemplate.update("delete from follow_state where user_id=? and fans_id=?",
                userId, fanId);
    }

    public boolean isFollowed(Long userId, Long fansId) {
        Integer count = jdbcTemplate.queryForObject("select count(1) from follow_state where user_id=? and fans_id=?",
                Integer.class, userId, fansId);
        return count != null && count > 0;
    }
}
